package com.webside.sensitiveWords.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webside.base.baseservice.impl.AbstractService;
import com.webside.sensitiveWords.mapper.SensitiveWordsMapper;
import com.webside.sensitiveWords.model.SensitiveWordsEntity;
import com.webside.sensitiveWords.service.SensitiveWordsService;
@Service("SensitiveWordsService")
public class SensitiveWordsServiceImpl extends AbstractService<SensitiveWordsEntity, Long> implements SensitiveWordsService{
	@Autowired
	private SensitiveWordsMapper sensitiveWordsMapper;
	//这句必须要加上。不然会报空指针异常，因为在实际调用的时候不是BaseMapper调用，而是具体的mapper，这里为userMapper
			@Autowired
			public void setBaseMapper() {
				super.setBaseMapper(sensitiveWordsMapper);
			}
	@Override
	public List<SensitiveWordsEntity> selectAllWords(Map<String, Object> paramter) {
		// TODO Auto-generated method stub
		return sensitiveWordsMapper.selectAllSensitiveWords(paramter);
	}

	@Override
	public List<SensitiveWordsEntity> selectByWord(Map<String, Object> paramter) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int addSensitiveWords(SensitiveWordsEntity paramter) {
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// 可以方便地修改日期格式
		String nowTime = dateFormat.format(now);
		paramter.setCreateTime(nowTime);
		sensitiveWordsMapper.addSensitiveWord(paramter);
		int i =0;
		if(!sensitiveWordsMapper.selectSensitiveWords(paramter).isEmpty()){
			i=1;
		}
		return i;
	}

	@Override
	public int updateSensitiveWords(SensitiveWordsEntity paramter) {
		// TODO Auto-generated method stub
		return sensitiveWordsMapper.updateSensitiveWord(paramter);
	}

	@Override
	public int deleteSentiveWords(List<String> paramter) {
		// TODO Auto-generated method stub
		
		return sensitiveWordsMapper.deleteSensitiveWord(paramter);
	}
	@Override
	public List<SensitiveWordsEntity> queryListByPage(Map<String, Object> param){
		return sensitiveWordsMapper.selectAllSensitiveWords(param);
	}
}
